// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   CategoryService.java

package com.itheima.travel.service;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.itheima.travel.dao.CategoryDao;
import com.itheima.travel.util.JedisUtil;
import java.util.List;
import redis.clients.jedis.Jedis;

public class CategoryService
{

	private CategoryDao categoryDao;

	public CategoryService()
	{
		categoryDao = new CategoryDao();
	}

	public String findAllCategory()
		throws Exception
	{
		String jsonData = null;
		Jedis jedis = null;
		try
		{
			jedis = JedisUtil.getJedis();
			jsonData = jedis.get("categoryList");
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		if (jsonData == null || "".equals(jsonData))
		{
			List categoryList = categoryDao.findAllCategory();
			jsonData = (new ObjectMapper()).writeValueAsString(categoryList);
			try
			{
				jedis.set("categoryList", jsonData);
			}
			catch (Exception e)
			{
				e.printStackTrace();
			}
		}
		try
		{
			jedis.close();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		return jsonData;
	}
}
